<?php

require '../classes/imageClass.php';
require '../classes/albumClass.php';
require '../classes/connectionFactoryClass.php';
require '../classes/imageDao.php';
require '../classes/albumDao.php';
require '../classes/validates.php';



$image = new ImageClass();
$c = new ConnectionFactory();
$db = $c->getConnection();
$imageDao = new imageDao($db);
$albumDao = new albumDao($db);
$valid = new validates();

//buscando albuns
$albuns = $albumDao->getAlbuns('', '');


if ($albuns) {
    foreach ($albuns as $a) {
        $dir = '../' . $a->getDirectory() . $a->getNameUser() . '/' . $a->getNameAlbum();
        $diruser = '../' . $a->getDirectory() . $a->getNameUser();

//deleletando fotos existentes no album
        foreach (scandir($dir) as $item) {
            if ($item == '.' || $item == '..')
                continue;
            unlink($dir . DIRECTORY_SEPARATOR . $item);
        }

//deleta o album
        rmdir($dir);
        rmdir($diruser);
    }




    if ($imageDao->removeAll()) {
        if ($albumDao->removeAll()) {
            echo"<script> alert('Todas as fotos foram deletadas.'); 
          window.location='../index.php';</script>";
        }echo"<script> alert('Não foi possível deletar.'); 
          window.location='../index.php';</script>";
    }
    else
        echo"<script> alert('Não foi possível deletar.'); 
          window.location='../index.php';</script>";

    $user = $a->getDirectory() . $a->getNameUser();
    rmdir($user);
}
else
    echo"<script> alert('Não existe registros.'); 
          window.location='../index.php';</script>";
?>

